﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace LI4.Presentation
{
    public partial class MenuEstatisticas : Form
    {
        public SortedDictionary<string, int> anuncios;
        public SortedDictionary<string, int> ce;
        public SortedDictionary<string, int> cursos;

        public MenuEstatisticas()
        {
            InitializeComponent();
        }

        
        private void graficoAnunciosDistrito(ZedGraphControl zgc)
        {          
            // get a reference to the GraphPane
            zg1.GraphPane = new GraphPane(zg1.GraphPane.Rect, "Anúncios por distrito", "Distritos", "Nº Anúncios");
           GraphPane myPane = zg1.GraphPane;
           
           // Set the Titles

           // Make up some random data points



            string[] distritos= new string[anuncios.Count()];
            double[] nrdistritos = new double[anuncios.Count()];
            int i = 0;

            Color[] colorList = {Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple,Color.Silver,Color.SandyBrown,Color.Salmon,Color.Plum,
                                Color.Orchid,Color.Olive,Color.Moccasin,Color.MediumVioletRed,Color.MediumSeaGreen,Color.LimeGreen,Color.LemonChiffon,Color.Lavender,
                                Color.Indigo};
            

            foreach(KeyValuePair<string, int> par in anuncios)
            {
               distritos[i]=par.Key;
               nrdistritos[i] = par.Value;
               myPane.AddPieSlice(nrdistritos[i],colorList[i],Color.White,45f,0,distritos[i]);
               i++;
            }
                      
            myPane.XAxis.Scale.TextLabels = distritos;
           // Set the XAxis to Text type

           myPane.XAxis.Type = AxisType.Text;
           
           // Fill the Axis and Pane backgrounds
           
           myPane.Chart.Fill = new Fill( Color.White,
                 Color.FromArgb( 255, 255, 166), 90F );
           myPane.Fill = new Fill( Color.FromArgb( 250, 250, 255) );
           
           // Tell ZedGraph to refigure the

           // axes since the data have changed

           zg1.AxisChange();
           zg1.Refresh();
               
        }

        private void graficoCursosDistrito(ZedGraphControl zgc)
        {
            // get a reference to the GraphPane
            zg1.GraphPane = new GraphPane(zg1.GraphPane.Rect, "Cursos por distrito", "Distritos", "Nº Cursos");
            GraphPane myPane = zg1.GraphPane;

            
            // Make up some random data points



            string[] distritos = new string[cursos.Count()];
            double[] nr = new double[cursos.Count()];
            int i = 0;

            Color[] colorList = {Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple,Color.Silver,Color.SandyBrown,Color.Salmon,Color.Plum,
                                Color.Orchid,Color.Olive,Color.Moccasin,Color.MediumVioletRed,Color.MediumSeaGreen,Color.LimeGreen,Color.LemonChiffon,Color.Lavender,
                                Color.Indigo};


            foreach (KeyValuePair<string, int> par in cursos)
            {
                distritos[i] = par.Key;
                nr[i] = par.Value;
                myPane.AddPieSlice(nr[i], colorList[i], Color.White, 45f, 0, distritos[i]);
                i++;
            }


            myPane.XAxis.Scale.TextLabels = distritos;
            // Set the XAxis to Text type

            myPane.XAxis.Type = AxisType.Text;

            // Fill the Axis and Pane backgrounds


            myPane.Chart.Fill = new Fill(Color.White,
                  Color.FromArgb(255, 255, 166), 90F);
            myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));

            // Tell ZedGraph to refigure the

            // axes since the data have changed

            zg1.AxisChange();
            zg1.Refresh();

        }

        private void graficoCandidatosEmpresas(ZedGraphControl zgc)
        {

            // get a reference to the GraphPane
            zg1.GraphPane = new GraphPane(zg1.GraphPane.Rect, "Utilizadores", "", "");
            GraphPane myPane = zg1.GraphPane;

            // Set the Titles


            // Make up some random data points



            string[] labels = new string[ce.Count()];
            double[] nr = new double[ce.Count()];
            int i = 0;

            Color[] colorList = {Color.Red, Color.Green, Color.Blue, Color.Purple};


            foreach (KeyValuePair<string, int> par in ce)
            {
                labels[i] = par.Key;
                nr[i] = par.Value;
                myPane.AddPieSlice(nr[i], colorList[i], Color.White, 45f, 0, labels[i]);
                i++;
            }
            
            myPane.XAxis.Scale.TextLabels = labels;
            // Set the XAxis to Text type

            myPane.XAxis.Type = AxisType.Text;

            // Fill the Axis and Pane backgrounds


            myPane.Chart.Fill = new Fill(Color.White,
                  Color.FromArgb(255, 255, 166), 90F);
            myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));

            // Tell ZedGraph to refigure the

            // axes since the data have changed

            zg1.AxisChange();
            zg1.Refresh();

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string op = treeView1.SelectedNode.Text;
            if (op.Equals("Anúncios"))
                graficoAnunciosDistrito(zg1);
            else if (op.Equals("Cursos"))
                graficoCursosDistrito(zg1);
            else if (op.Equals("Utilizadores"))
                graficoCandidatosEmpresas(zg1);

        }

        private void MenuEstatisticas_Load(object sender, EventArgs e)
        {
            /*this.treeView1.SelectedNode = treeNode2;
            
            Data.Estatistica estat = new LI4.Data.Estatistica();
            anuncios = estat.getAnunciosDistrito();
            ce = estat.getCandidatosEmpresas();
            cursos = estat.getCursosDistrito();*/

        }

    }
}
